package com.zyw.security.shiro.web.realm;

import com.zyw.security.shiro.web.authc.AuthService;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 基础 authorizing realm
 *
 * @author zhangyw
 * @date 2018/1/25 9:55
 */
public abstract class BasicAuthRealm extends AuthorizingRealm {

    protected final Logger logger = LoggerFactory.getLogger(getClass());

    private AuthService authService;

    protected AuthService getAuthService() {
        assertRealmsConfigured();
        return authService;
    }

    public void setAuthService(AuthService authService) {
        this.authService = authService;
    }

    protected void assertRealmsConfigured() {
        if (authService == null) {
            String msg = "Configuration error:  No auth service have been configured for " + getClass().getName();
            throw new IllegalStateException(msg);
        }
    }

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        return null;
    }
}
